"""
 * Input: candidates = [2,3,6,7], target = 7,
 * A solution set is:
 * [
 * ⁠ [7],
 * ⁠ [2,2,3]
 * ]
 *
 *
 * Example 2:
 *
 *
 * Input: candidates = [2,3,5], target = 8,
 * A solution set is:
 * [
 * [2,2,2,2],
 * [2,3,3],
 * [3,5]
 * ]
"""
from typing import Set, List


def find_sum(candidates: List[int], target: int)->Set[List[int]]:
    if target <= 0 or not candidates:
        return set()
    can_num = len(candidates)
    res = set()
    path = []
    candidates.sort()
    find_path(candidates, target, 0, can_num, res, path)
    return res

def find_path(candidates, target, start, end, res, path):
    if target == 0:
        res.add(tuple(path))
    for i in range(start, end):
        val = candidates[i]
        left = target - val
        if left < 0:
            break
        path.append(val)
        find_path(candidates, left, i, end, res, path)
        path.pop()

print(find_sum([2,3,5], 8))